﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMIS.Dals;
using SMIS.Entities;

namespace SMIS
{
    public partial class FormIncome : Form
    {
        public FormIncome()
        {
            InitializeComponent();
        }

        //【高月 2013-3-31-165125】这是此页面需要初始化的数据
        private void FormIncome_Load(object sender, EventArgs e)
        {
            List<Income> dtIncome = Dal4Income.SearchAllIncomes();
            gvIncomes.DataSource = dtIncome;

            CommonUtil.BindData4ComboBox(cboStaff, Dal4Income.GetStaffs(), "SName", "SID");
            //DataTable dtSelectedStaff = Dal4Income.GetStaffs();
            //cboStaff.DataSource = dtSelectedStaff;
            //cboStaff.DisplayMember = "SName";
        }

        //【高月 2013-3-31-165044】按员工名字筛选的查询按钮事件
        private void button4_Click(object sender, EventArgs e)
        {
            
            string staff = cboStaff.Text;
            List<Income> incomes = Dal4Income.SearchSelectedStaffIncomes(staff);
            gvIncomes.DataSource = incomes;
        }

        //【高月 2013-3-31-164958】收入修改按钮事件
        private void button1_Click(object sender, EventArgs e)
        {
            //【高月 2013-3-31-164402】把这个窗口中我选中那行的数据传递到ModifyIncome窗口中去
            if (gvIncomes.SelectedRows.Count == 0)
                MessageBox.Show("请选择要修改的行！", "提示");
            else
            {
                Income selectedIncome = gvIncomes.SelectedRows[0].DataBoundItem as Income;
                ModifyIncome modifyIncome = new ModifyIncome();
                //modifyIncome.MdfName = selectedIncome.Staff;(【高月 2013-3-31-164149】注释掉是因为下面通过DataTable的方式传值进来的)
                modifyIncome.MdfMonth = selectedIncome.Month;
                modifyIncome.MdfIncome = selectedIncome.Incomes;
                modifyIncome.MdfRemark = selectedIncome.Remark;
                modifyIncome.MdfID = selectedIncome.ID;

                modifyIncome.ShowDialog();
            }
        }

        //【高月 2013-3-31-165012】收入删除按钮事件
        private void button2_Click(object sender, EventArgs e)
        {
            if (gvIncomes.SelectedRows.Count == 0)
                MessageBox.Show("请选择要删除的行！", "提示");
            else
            {
                Income selectedIncome = gvIncomes.SelectedRows[0].DataBoundItem as Income;
                if (MessageBox.Show(string.Format("确定要删除员工【{0}】【{1}】的收入信息？", selectedIncome.Staff, selectedIncome.Month), "确认信息",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    Dal4Income.DeleteIncome(selectedIncome);
                    MessageBox.Show("删除员工收入信息成功！", "提示");
                    //我想在删除成功这个信息窗口上点击确认后，让gvIncomes能自动刷新数据，但是下面这个写上去无效，怎么办？
                    //Dal4Income.SearchAllIncomes();
                }
            }
        }

        //【高月 2013-3-31-165027】收入取消按钮事件
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
